/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Proyecto.graphicInterface;

import Proyecto.Logico.Coordenada;
import Proyecto.Logico.Logico;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author LFBP
 */
public class VentanaPrincipal extends JFrame implements ActionListener{
    
    private JPanel pnlMenu;
    private JButton btnPintar, btnSalir;
    private JTextField txtCorX,txtCorY;
    private JLabel lblCorX,lblCorY;
    private Lienzo lienzo;
    private Logico logic;
    
    public VentanaPrincipal(){
        
        btnSalir = new JButton("SALIR");
        btnSalir.addActionListener(this);
        btnSalir.setActionCommand("S");
        
        logic = new Logico();
        logic.leerArchivo();
        pnlMenu = new JPanel(new GridLayout(3, 2));
        
        lblCorX = new JLabel("Coordenada X:");
        lblCorY = new JLabel("Coordenada Y:");
        
        btnPintar = new JButton("PINTAR");
        btnPintar.addActionListener(this);
        btnPintar.setActionCommand("B");
        
        txtCorX = new JTextField();
        txtCorY = new JTextField();
        
        pnlMenu.add(lblCorX);
        pnlMenu.add(txtCorX);
        pnlMenu.add(lblCorY);
        pnlMenu.add(txtCorY);
        pnlMenu.add(btnPintar);
        pnlMenu.add(btnSalir);
        
        lienzo = new Lienzo(logic, txtCorX, txtCorY);
        
        add(pnlMenu,BorderLayout.SOUTH);
        add(lienzo,BorderLayout.CENTER);
        
        setSize(1000,650);
        setVisible(true);
        
        
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        
        if(e.getActionCommand().equals("B")){
            Coordenada coor = new Coordenada(Float.parseFloat(txtCorX.getText()),Float.parseFloat(txtCorY.getText()));
        
            logic.addArray(coor);
            logic.guardarArchivo();

            lienzo.repaint();
        }else{
            System.exit(0);
        }
    }
    
    public static void main (String args [] ){
        
        VentanaPrincipal a = new VentanaPrincipal();
    }
}
